<%@ include file="/WEB-INF/common/taglibs.jsp"%>
<script type="text/javascript"> 
var deal='';
$(document).ready(function(){	
	$("#table_deals").tableSorter({
		sortClassAsc: 'headerSortUp',
		sortClassDesc: 'headerSortDown',
		headerClass: 'header',
		disableHeader: true
	}).tableEditor({
		EDIT_HTML: 'Edit',
		SAVE_HTML: 'Save',
		FUNC_PRE_EDIT: 'preEdit',
		FUNC_PRE_SAVE: 'preSave',
		FUNC_UPDATE: 'updateTable'
	});
});
function preEdit(o){
	var col=o.row[8];
	var val=o.row[8].innerHTML;
	var html="<select><option value='true'>true</option><option value='false'>false</option></select>";
	$(col).html(html).find('select option').each(function() {
		if ($(this).html() == val)
			$(this).attr("selected", true);
	});
}
function preSave(o){
	deal='';
	o.row.find("input, select").each(function(){
		deal += $(this).val()+"-,-";
	}).end();
}
function updateTable(o){
	$.ajax({
		url: 'updateDeal.htm?deal=' + deal,
		type: 'POST',
		timeout: 3000,
		error: function(){alert('update failed!');},
		success: function(){
			alert('update done.');
			var col=o.row[8];
			var val;
			o.row.find("select").each(function(){
				val=$(this).val();
			}).end();
			$(col).html(val);
		}
	});
}
</script>
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all"
	style="float: center; margin: 0 auto;"><c:if
	test="${param.index gt 0}">
	<a
		href="<c:url value="/admin/manageDeals.htm?index=${param.index-1}"/>">previous
	page</a>
</c:if>&nbsp;&nbsp;<a
	href="<c:url value="/admin/manageDeals.htm?index=${param.index+1}"/>">next
page</a></div>
<table align="center" id="table_deals">
	<thead>
		<tr>
			<th>Id</th>
			<th style="width: 100px;">City</th>
			<th>Vendor</th>
			<th style="width: 375px;">Description</th>
			<th>Price</th>
			<th>Value</th>
			<th>Saving</th>
			<th>EndTime</th>
			<th style="width: 60px;">OnlineDeal</th>
			<th style="width: 40px;">Action</th>
		</tr>
	</thead>
	<tbody>
		<c:forEach var="deal" items="${deals}">
			<tr>
				<td>${deal.id}</td>
				<td>${deal.city}</td>
				<td>${deal.source}</td>
				<td>${deal.title}</td>
				<td>${deal.price}</td>
				<td>${deal.retailValue}</td>
				<td>${deal.discount}</td>
				<td>${deal.timeEnd}</td>
				<td>${deal.onlineDeal}</td>
				<td><a href="#" class="tsEditLink">Edit</a></td>
			</tr>
		</c:forEach>
	</tbody>
</table>
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all"
	style="float: center; margin: 0 auto;"><c:if
	test="${param.index gt 0}">
	<a
		href="<c:url value="/admin/manageDeals.htm?index=${param.index-1}"/>">previous
	page</a>
</c:if>&nbsp;&nbsp;<a
	href="<c:url value="/admin/manageDeals.htm?index=${param.index+1}"/>">next
page</a></div>
